﻿using System.Collections.Generic;
using System.Linq;
using Airborne.ScrumPoker.Properties;

namespace Airborne.ScrumPoker.Model.Cards
{
    public static class CardFactory
    {
        private static double[] FibonacciSequence = { 0, 0.5, 1, 2, 3, 5, 8, 13, 20, 40, 100, -999, -998 };


        //public static ICard[] CreateSequence(GameMode mode)
        //{
        //    switch (mode)
        //    {
        //        case GameMode.StoryCardEstimation:
        //            return CreateSequence();
        //         case GameMode.TShirtSizing:
        //            return CreateTShirtSequence();
        //        default:
        //            return CreateSequence();
        //    }
        //}

        //public static ICard[] CreateTShirtSequence()
        //{
        //    List<ICard> cards = new List<ICard>();

        //    cards.Add(new SimpleCard() { ActualValue = 0, CardFaceValue = "0" });
        //    cards.Add (new SimpleCard() { ActualValue = 2, CardFaceValue = "XS" });
        //    cards.Add(new SimpleCard() { ActualValue = 5, CardFaceValue = "S" });
        //    cards.Add(new SimpleCard() { ActualValue = 8, CardFaceValue = "M" });
        //    cards.Add(new SimpleCard() { ActualValue = 13, CardFaceValue = "L" });
        //    cards.Add(new SimpleCard() { ActualValue = 20, CardFaceValue = "XL" });
        //    cards.Add(new SimpleCard() { ActualValue = 40, CardFaceValue = "XXL" });
        //    cards.Add(new SimpleCard() { ActualValue = 100, CardFaceValue = "XXXL" });

        //    cards.Add(new SimpleCard() { ActualValue = -999, CardFaceValue = "?" });
        //    cards.Add(new SimpleCard() { ActualValue = -998, CardFaceValue = Resources.TakeABreak });

        //    return cards.ToArray();
        //}

        public static ICard[] CreateSequence()
        {
            List<ICard> cards = new List<ICard>();
            foreach (double item in FibonacciSequence)
            {
                SimpleCard card = new SimpleCard() { ActualValue = item, CardFaceValue = item };
                if (card.ActualValue == -999)
                {
                    card.CardFaceValue = "?";
                }
                if (card.ActualValue == -998)
                {
                    card.CardFaceValue = Resources.TakeABreak;
                }
                cards.Add(card);
            }
            return cards.ToArray();
        }

        public static ICard GetCard(double cardValue)
        {
            ICard[] cards = CreateSequence();
            var selected = from c in cards
                           where c.ActualValue == cardValue
                           select c;

            return selected.FirstOrDefault();
        }
    }
}
